<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\BaseController;
use App\Models\VoiceTranslate;
use Illuminate\Http\Request;

class VoiceTranslateController extends BaseController
{

    public function store(Request $request)
    {
        $this->validate($request,[
            'animal_type'=> 'required|in:1,2',
            'request_file_path' => 'required',
        ]);
        $input = $request->input();
        $animal_type = $request->input('animal_type');
        $user_id =  $this->getUserId();
        $user_id = $user_id ?: $request->header('fake_uid');
        $input['user_id'] = $user_id;
        if ($animal_type == VoiceTranslate::TYPE_CAT) {
            $file_path = env('QINIU_URL') . '/cat_voice'.mt_rand(0, 159).'.m4a';
        } else {
            $file_path = env('QINIU_URL') . '/dog_voice'.mt_rand(0, 99).'.m4a';
        }
        $input['response_file_path'] = $file_path;
        VoiceTranslate::create($input);
        return $this->success(compact('file_path'));
    }

}

